package com.jp.executor;

import java.util.concurrent.*;

public class ExecutorTest {

    public static void main(String[] args) throws InterruptedException {
        Executor executor;
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 20,
                5, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10));
        threadPoolExecutor.prestartCoreThread();
        threadPoolExecutor.prestartCoreThread();
        threadPoolExecutor.prestartAllCoreThreads();


        try {
            TimeUnit.SECONDS.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        threadPoolExecutor.allowCoreThreadTimeOut(true);

        threadPoolExecutor.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("run");
                try {
                    TimeUnit.SECONDS.sleep(5);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        TimeUnit.SECONDS.sleep(30);
        System.out.println("poolSize=" + threadPoolExecutor.getPoolSize());
        threadPoolExecutor.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("run");
            }
        });
    }

}
